package com.songlanyun.modules.shop.controller.api;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import com.songlanyun.common.utils.R;

import com.songlanyun.modules.shop.entity.UnionBusinessClassifyEntity;
import com.songlanyun.modules.shop.service.UnionBusinessClassifyService;
import com.songlanyun.modules.user.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 联盟商家分类
 *
 * @author WuChao
 * @email songlanyun@gmail.com
 * @date 2022-11-21 14:38:04
 */
@RestController
@RequestMapping("api/union/business/classify")
public class UnionBusinessClassifyApiController extends AbstractController {
    @Autowired
    private UnionBusinessClassifyService unionBusinessClassifyService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        Integer limit = MapUtil.getInt(params, "limit");

        List<UnionBusinessClassifyEntity> list = unionBusinessClassifyService.lambdaQuery()
                .eq(UnionBusinessClassifyEntity::getIsShow, true)
                .orderByAsc(UnionBusinessClassifyEntity::getRank)
                .orderByDesc(UnionBusinessClassifyEntity::getCreateTime)
                .last(ObjectUtil.isNotNull(limit), "limit " + limit)
                .list();
        return R.ok().put("list", list);
    }

}
